home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 5160 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: shell1.eznet.net!not-for-mail
  2. From: armstron@eznet.net (Jon Armstrong)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Referances troubble
  5. Date: 10 Mar 1996 11:02:45 -0500
  6. Organization: E-Znet, Incorporated, Rochester, New York (716) 262-2485
  7. Message-ID: <4huuf5$gih@shell1.eznet.net>
  8. References: <1266.6624T117T1455@himolde.no> <4gspc8$dj4@oak42.doc.ic.ac.uk>
  9. NNTP-Posting-Host: shell1.eznet.net
  10.  
  11. Martin Frost <mdf@doc.ic.ac.uk> wrote:
  12.  
  13. Hello Martin.
  14.  
  15. Maybe we can solve your problem as well. Maybe it was a simple typo. :)
  16.  
  17. >If I understand you correctly, this is the sort of thing you need:
  18.  
  19. The following is nearly the type of thing the poster wanted, except
  20. this code also has a bug or two.  The function definition/declaration
  21. is fine, but the way it assigns p1 and p2 is incorrect.
  22.  
  23. >void func(void **p1, void **p2)
  24. >  {
  25. >  printf("%lx,%lx\n",p1,p2);
  26.  
  27. Change the following:
  28.  
  29. >  p1 = AllocMem(100,MEMF_CHIP|MEMF_CLEAR);
  30. >  p2 = AllocMem(200,MEMF_ANY);
  31. >  printf("%lx,%lx\n",p1,p2);
  32.  
  33. to this:
  34.  
  35.   *p1 = AllocMem(100,MEMF_CHIP|MEMF_CLEAR);
  36.   *p2 = AllocMem(200,MEMF_ANY);
  37.    printf("%lx,%lx\n",*p1,*p2);
  38.  
  39. >  }
  40.  
  41. >int main(void)        /* NOTE WELL: main() returns an _int_ */
  42.  
  43. As it should.
  44.  
  45. >  {
  46. >  void *p1,*p2;
  47. >  printf("%lx,%lx\n",p1,p2);
  48. >  func(&p1,&p2);
  49. >  printf("%lx,%lx\n",p1,p2);
  50. >  if(p1) FreeMem(p1,100);
  51. >  if(p2) FreeMem(p2,200);
  52. >  return(0);
  53. >  }
  54.  
  55. main looks fine, for the purposes of this matter, at least.
  56.  
  57. Aside:  I prefer to wrap all Amiga specific calls that easily port
  58. to other environments, like unix.  This allows for a much easier time
  59. testing and porting of course, if you work on both Amiga and non-Amiga
  60. platforms.
  61.  
  62. I would rarely call AllocMem() or FreeMem() directly, due to the
  63. work I'm normally involved with.
  64.  
  65. A reasonable alternative is to provide a macro or interface
  66. replacement for those functions on alternate platforms.
  67.  
  68. #define AllocMem(__size,__type) calloc(1,__size)
  69. #define FreeMem(__ref,__size)   free(__ref)
  70.  
  71. I usually opt for the standard malloc/calloc/free, or versions
  72. which provide resource tracking, but I realize the necessity to
  73. specify things like MEMF_CHIP, from time to time, in the Amiga
  74. environment.
  75.  
  76. Just a thought.
  77.  
  78. Regards... Jon ( #C - Xgc - Please, join us on irc sometime. )
  79.  
  80. -- 
  81.                +----------------------------------------------+
  82. Regards... Jon | Armstrong | LPA Software, Inc. | jma@lpa.com |
  83.                +----------------------------------------------+
  84.